from pymongo import MongoClient

# 數據庫名
DATABASE_NAME = "rel"

# mongo host
HOST = "10.141.7.94"
# HOST = "10.134.82.195"

# mongo port
PORT = 27017

USERNAME = 'F7691717'
PASSWORD = 'F7691717'
PROFILE_USERNAME = 'f7689984'
PROFILE_PASSWORD = 'f7689984'

MONGO_URL = 'mongodb://' + PROFILE_USERNAME + ':' + PROFILE_PASSWORD + '@' + HOST + ':' + str(
    PORT) + '/?authSource=flask_profiler'


# 建立mongodb连接实例
class MongoConnect(object):
    """创建一个连接到bm-hub数据库的mongo连接"""

    def __init__(self):
        print('初始化mongodb')
        # # 建立mongodb连接
        # client = MongoClient('10.141.7.94', 27017)
        # # 连接到bm_hub 数据库
        # client_db = client.bm_hub

    @property
    def conn(self):
        # 连接到bm_hub 数据库
        if not hasattr(self, '_conn'):
            self.getconnection()
        return self._conn.rel

    def getconnection(self):
        self._conn = MongoClient(HOST, 27017, connect=False, authSource=DATABASE_NAME, username=USERNAME,
                                 password=PASSWORD)


mongoClient = MongoConnect().conn
